package com.snow.useviewdemo.function.calendar;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.snow.common.base.CustomViewPagerAdapter;
import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;
import com.snow.useviewdemo.databinding.ActCalenadarCustomBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * author : zyt
 * e-mail : 632105276@qq.com
 * date   : 2019-12-25
 * desc   :自定义日历测试==支持左右滑动切换
 *      缺点：需要提前设置fragment的个数，不能无限制添加
 */
public class CalendarCustomActivity extends BaseActivity<ActCalenadarCustomBinding> {
    CustomViewPagerAdapter mAdapter;
    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.act_calenadar_custom;
    }

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        mAdapter = new CustomViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        mBinding.viewPager.setAdapter(mAdapter);
        mBinding.viewPager.setOffscreenPageLimit(5);
        initListener();
        initData();
    }

    private void initData() {
        int year = CalendarUtils.init().getCurrentYear();
//        for (int i = 0; i < 5; i++) {
//            year
//        }
        for (int i = 1; i < 100; i++) {
            fragmentList.add(CalendarFragment.getInstance(year,i));
        }
        mAdapter.notifyDataSetChanged();
        mBinding.viewPager.setCurrentItem(50);
    }

    private void initListener() {
//        mBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                fragmentList.add(CalendarFragment.getInstance("2019-11"));
//                mAdapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
    }
}
